***********************************************************************************
********"Macroprudential Regulation, Quantitative Easing, and Bank Lending"********
***********************************************************************************
* This file merges several datasets to extend the analysis 
* to all monetary policy shocks at the long-end of the yield curve.
***********************************************************************************
***********************************************************************************

*==================================================================================
**# Bookmark (input)
clear *
use $inputdirectory/INB_assetsmonpol, clear

merge 1:1 bankid time using $inputdirectory/INB_cashmonpol
keep if _merge!=2
drop _merge

merge 1:1 bankid time using $inputdirectory/INB_ecbdepomonpol
keep if _merge!=2
drop _merge

merge 1:1 bankid time using $inputdirectory/INB_refinmonpol
keep if _merge!=2
drop _merge

merge 1:1 bankid time using $inputdirectory/INB_isinmonpol
keep if _merge!=2
drop _merge 

merge 1:1 bankid time using $inputdirectory/INB_isinmonpol2
keep if _merge!=2
drop _merge 

merge 1:1 bankid time using $inputdirectory/INB_isinmonpol3
keep if _merge!=2
drop _merge

merge 1:1 bankid time using $inputdirectory/INB_isinmonpol4
keep if _merge!=2
drop _merge 

recode ecbdepo lncrefin cash book* (.=0)
xtset bankid time

gen laghca=.
replace laghca=100*((L.book1+L.book2)/L.assets) if time<tm(2018m2)
replace laghca=100*((L.book1)/L.assets) if time>=tm(2018m2)

gen lagmma=.
replace lagmma=100*((L.book3)/L.assets) if time<tm(2018m2)
replace lagmma=100*((L.book3+L.book2)/L.assets) if time>=tm(2018m2)

gen lag2mma=.
replace lag2mma=100*((L2.book3)/L2.assets) if time<tm(2018m2)
replace lag2mma=100*((L2.book3+L2.book2)/L2.assets) if time>=tm(2018m2)

gen lag3mma=.
replace lag3mma=100*((L3.book3)/L3.assets) if time<tm(2018m2)
replace lag3mma=100*((L3.book3+L3.book2)/L3.assets) if time>=tm(2018m2)

gen lagmmam5=.
replace lagmmam5=100*((L.book3m5)/L.assets) if time<tm(2018m2)
replace lagmmam5=100*((L.book3m5+L.book2m5)/L.assets) if time>=tm(2018m2)

gen lagmmap2=.
replace lagmmap2=100*((L.book3p2)/L.assets) if time<tm(2018m2)
replace lagmmap2=100*((L.book3p2+L.book2p2)/L.assets) if time>=tm(2018m2)

gen lagmmaall=.
replace lagmmaall=100*((L.book3all)/L.assets) if time<tm(2018m2)
replace lagmmaall=100*((L.book3all+L.book2all)/L.assets) if time>=tm(2018m2)

gen lagbook1=100*((L.book1)/L.assets)
gen lagbook1m5=100*((L.book1m5)/L.assets)
gen lagbook3=100*((L.book3)/L.assets)
gen lagafs=100*(L.book2/L.assets)

gen lagbook3m5=100*((L.book3m5)/L.assets)
gen lagafsm5=100*(L.book2m5/L.assets)

gen laglnassets=ln(L.assets)
gen lagcashas=100*((L.ecbdepo+L.cash)/L.assets)

keep bankid time laghca lagmma lag2mma lag3mma lagmmam5 lagmmap2 lagmmaall lagafs* lagbook3* lagbook1* lncrefin laglnassets lagcashas
keep if time>=tm(2010m1)&time<=tm(2020m2)

**# Bookmark (saving dataset - exposure and other variables)
compress 
save $inputdirectory/INB_contr&expmonpol, replace

erase $inputdirectory/INB_assetsmonpol.dta
erase $inputdirectory/INB_refinmonpol.dta
erase $inputdirectory/INB_ecbdepomonpol.dta
erase $inputdirectory/INB_cashmonpol.dta
